package com.hanhanxiaochong.zhongxiangchuanmei.view.shop.act;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.ShopTypeBean;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.ShopNextPresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.home.GoodListActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IShopNextView;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.act.MsgActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.shop.adapter.ShopNextFirstAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.shop.adapter.ShopNextSecondAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/5/9.
 * Desc   : 商品二级页面
 */

public class ShopNextActivity extends BaseActivity<ShopNextPresenter> implements IShopNextView {

    @BindView(R.id.et_home_search)
    EditText etHomeSearch;
    @BindView(R.id.recyclerview_first)
    RecyclerView recyclerviewFirst;
    @BindView(R.id.recyclerview_second)
    RecyclerView recyclerviewSecond;

    private List<ShopTypeBean.TypeBean> firstTypeList = new ArrayList<>();

    private ShopNextFirstAdapter shopNextFirstAdapter;
    private ShopNextSecondAdapter ShopNextSecondAdapter;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_shop_next);
    }

    @Override
    protected void initPresenter() {
        mPresenter = new ShopNextPresenter(this);
    }

    @Override
    protected void init() {
        mPresenter.getFirstShopType();
        recyclerviewFirst.setLayoutManager(new LinearLayoutManager(mContext));
//        recyclerviewSecond.setLayoutManager(new GridLayoutManager(mContext, 3));

        List<ShopTypeBean.TypeBean> list = new ArrayList<>();
        shopNextFirstAdapter = new ShopNextFirstAdapter(mContext, R.layout.item_shopnext_first,
                list);
        shopNextFirstAdapter.setmOnItemClickListener((adapter, position) -> {
//            mPresenter.getSecondShopType(firstTypeList.get(position).getId());
            startActivity(GoodListActivity.createIntent(this, firstTypeList.get(position).getId(), null));
        });
//        ShopNextSecondAdapter = new ShopNextSecondAdapter(mContext, R.layout.item_shopnext_second,
//                list);
//        ShopNextSecondAdapter.setmOnItemClickListener((arg0, arg1) -> {
//            startActivity(GoodListActivity.createIntent(this, ShopNextSecondAdapter.getDatas().get(arg1).getId(), null));
//            finish();
//        });
//        recyclerviewSecond.setAdapter(ShopNextSecondAdapter);
        recyclerviewFirst.setAdapter(shopNextFirstAdapter);

    }

    @OnClick({R.id.ll_left, R.id.img_home_msg})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_left:
                finish();
                break;
            case R.id.img_home_msg:
                Intent intent = new Intent(mContext, MsgActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void setFirstLevel(List<ShopTypeBean.TypeBean> type) {
        firstTypeList = type;
        shopNextFirstAdapter.addDatas(type);
    }

    @Override
    public void setSecondLevel(List<ShopTypeBean.TypeBean> type) {
        ShopNextSecondAdapter.setDatas(type);
    }
}
